function getSelector(path) {
    // console.log(path,'path')
 return path
    .reverse()
    .filter((element) => {
      return element !== document && element !== window;
    })
    .map((item) => {
       
      let selector = "";
      if (item.id) {
        return `${item.nodeName.toLowerCase()}#${item.id}`;
      }else if (item.className && typeof item.className=='string'){
          return `${item.nodeName.toLowerCase()}.${item.className}`
      }else{
        selector = item.nodeName.toLowerCase()
      }
      return  selector
    }).join('');
    
}

export default function (pathsOrTarget) {
  if (Array.isArray(pathsOrTarget)) { //可能是一个数组
    return getSelector(pathsOrTarget);
  }else{//也有可能是一个对象
    let path = [];
    while(pathsOrTarget){
      path.push(pathsOrTarget)
      pathsOrTarget= pathsOrTarget.parentNode
    }
    return  getSelector(path);
  }
}
